package com.oscar.practice.shiro.action.user;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.oscar.practice.shiro.biz.user.PermissionBiz;
import com.oscar.practice.shiro.dao.user.PermissionDao;
import com.oscar.practice.shiro.model.user.PermissionInfo;
import com.oscar.practice.shiro.util.lang.JsonUtil;

/**
 * 权限
 *
 * @author tongyufu
 *
 */
@RestController
@RequestMapping("/admin/permission")
public class PermissionAction {

    @Autowired
    private PermissionBiz permissionBiz;
    @Autowired
    private PermissionDao permissionDao;

    @RequestMapping("search")
    public String search(@RequestParam Map<String, Object> params) {
        return JsonUtil.toJson(permissionBiz.search(params));
    }

    /**查询指定角色的权限树*/
    @RequestMapping("queryByRole")
    public List<Map<String, Object>> queryByRole(Integer roleId) {
        return permissionBiz.queryByRole(roleId);
    }

    @RequestMapping("queryById")
    public PermissionInfo queryById(Integer id) {
        return permissionDao.queryById(id);
    }

    @RequestMapping("save")
    public String save(PermissionInfo permissionInfo) {
        return permissionBiz.save(permissionInfo);
    }

    @RequestMapping("delete")
    public String delete(Integer id) {
        return permissionBiz.delete(id);
    }

}
